package com.douqu.game.auth.web.controller;


import com.douqu.game.auth.service.ServerService;
import com.douqu.game.auth.web.request.QueryTotalRechargeReqDto;
import com.douqu.game.auth.web.request.UseCodeReqDto;
import com.douqu.game.core.database.model.MergeModel;
import com.douqu.game.core.factory.HttpFactory;
import com.douqu.game.core.util.LogUtils;
import com.douqu.game.core.web.response.BaseResponseDto;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * Author : wangzhenfei
 * 2017-07-06 15:55
 */
@RestController
public class ServerController {
    @Autowired
    private ServerService serverService;

    /**
     * @return
     */
    @RequestMapping(value = "/server/test", method = { RequestMethod.GET, RequestMethod.POST })
    public void test(HttpServletRequest request) {

        LogUtils.info("测试HTTP,来自 -> " + request.getRemoteAddr() + "   " + request.getRemoteHost());
        LogUtils.info("  " + request.getLocalAddr());
    }


    @RequestMapping(value = HttpFactory.SERVER_CHANGE_STATUS, method = RequestMethod.POST, produces = "application/json;charset=UTF-8")
    public BaseResponseDto changeStatus(String password, Integer serverId, Integer status, String version)
    {
        return serverService.changeStatus(password, serverId, status, version);
    }


    @RequestMapping(value = HttpFactory.SERVER_USE_CDK_CODE, method = RequestMethod.POST, produces = "application/json;charset=UTF-8")
    public BaseResponseDto useCdkCode(@RequestBody UseCodeReqDto request)
    {
        return serverService.useCdkCode(request);
    }


    /**
     * GM工具调用的
     * @param areaId
     * @return
     */
    @RequestMapping(value = HttpFactory.SERVER_LIST, produces = "application/json;charset=UTF-8")
    public BaseResponseDto gmServerList(Integer areaId, String gmVersion)
    {
        return serverService.findServerList(areaId, gmVersion);
    }


    @RequestMapping(value = HttpFactory.SERVER_NOTIFY_ACTIVITY_SERVER_MAIN_SERVER_START, produces = "application/json;charset=UTF-8")
    public BaseResponseDto notifyActivityServerMainServerStart(Integer serverId)
    {
        return serverService.notifyActivityServerMainServerStart(serverId);
    }

    @RequestMapping(value = HttpFactory.SERVER_UPDATE_VERSION, produces = "application/json;charset=UTF-8")
    public BaseResponseDto updateVersion(Integer serverId, String version, String password)
    {
        return serverService.updateVersion(serverId, version, password);
    }

    @RequestMapping(value = HttpFactory.SERVER_GET_SERVER_INFO, produces = "application/json;charset=UTF-8")
     public BaseResponseDto getServerInfo(Integer id)
    {
        return serverService.getServerInfo(id);
    }

    @RequestMapping(value = HttpFactory.SERVER_GET_SERVER_TASK, produces = "application/json;charset=UTF-8")
    public BaseResponseDto getServerTask(Integer id)
    {
        return serverService.getServerTask(id);
    }


    @RequestMapping(value = HttpFactory.SERVER_GET_TOTAL_RECHARGE_COUNT, produces = "application/json;charset=UTF-8")
    public BaseResponseDto getTotalRechargeCount(@RequestBody QueryTotalRechargeReqDto request)
    {
        return serverService.getTotalRechargeCount(request);
    }

    @RequestMapping(value = HttpFactory.SERVER_NOTIFY_ACTIVITY_SERVER_MODIFY_SERVER_MODEL, produces = "application/json;charset=UTF-8")
    public BaseResponseDto notifyActivityServerModifyServerModel(Integer serverId)
    {
        return serverService.notifyActivityServerModifyServerModel(serverId);
    }

    /**
     * 通知活动服务器更新配置文件
     * @param path 云存储配置文件的路径
     * @param version 配置文件版本
     * @param password 密码
     * @return
     */
    @RequestMapping(value = HttpFactory.SERVER_NOTIFY_ACTIVITY_SERVER_UPDATE_CONFIG, produces = "application/json;charset=UTF-8")
    public BaseResponseDto notifyActivityServerUpdateConfig(Integer id, String path, String version, String password)
    {
        return serverService.notifyActivityServerUpdateConfig(id, path, version, password);
    }

    @RequestMapping(value = HttpFactory.SERVER_ACTIVITY_SERVER_LIST, produces = "application/json;charset=UTF-8")
    public BaseResponseDto getActivityServerList()
    {
        return serverService.getCampActivityServerList();
    }

    @RequestMapping(value = HttpFactory.SERVER_MERGE_READY,method = RequestMethod.POST ,produces = "application/json;charset=UTF-8")
    public BaseResponseDto mergeReady(@RequestBody MergeModel mergeModel, HttpServletRequest request, HttpServletResponse response){
        return serverService.mergeReady(mergeModel);
    }

    @RequestMapping(value = HttpFactory.SERVER_GET_ALL,method = RequestMethod.POST,produces = "application/json;charset=UTF-8")
    public BaseResponseDto getAllServer(HttpServletRequest request,HttpServletResponse response){
        return serverService.getAll();
    }
}
